Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9205155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:53:08+00:00 2026-06-17T23:53:08+00:00

static inline void ext4_ext_store_pblock(struct ext4_extent *ex, ext4_fsblk_t pb) { ex->ee_start_lo = cpu_to_le32((unsigned long) (pb

  • 0
static inline void ext4_ext_store_pblock(struct ext4_extent *ex,
                     ext4_fsblk_t pb)
{
    ex->ee_start_lo = cpu_to_le32((unsigned long) (pb & 0xffffffff));
    ex->ee_start_hi = cpu_to_le16((unsigned long) ((pb >> 31) >> 1) &
                      0xffff);
}

This code is from linux kernel.
See last line. it does pb>>31 then >>1
Is this same as pb >> 32
why not do that?

thank you

EDITED:
thank you all. sent patch to ext4 maillist

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T23:53:10+00:00Added an answer on June 17, 2026 at 11:53 pm

    The two approaches are not quite the same thing, depending on the underlying data types. The standard (C11, 6.5.7 Bitwise shift operators) states that:

    If the value of the right operand is negative or is greater than or equal to the width of the promoted left operand, the behavior is undefined.

    Hence, if you were to shift a 32-bit wide integer type 32 bits to the right, it would result in undefined behaviour. However, shifting it 31 bits and then another bit is well defined.

    That particular point, while a reason why someone may do this, is probably moot in this particular case. Given your type is unsigned long long (guaranteed 64 bits width), there should be no difference between (x >> 31) >> 1 and x >> 32.

    However, if some platform actually defines ext4_fsblk_t as a 32-bit type (or if it’s carried forward from an earlier implementation which allowed a 32-bit type (a)), you would find yourself having to resort to the two-stage shift to guarantee defined behaviour.


    (a): There was an interim stage between ext3 and ext4 which allowed ext3 to move to 48 bits with its extents, a stepping stone on the way to ext4 with its 64-bit data types. Prior to that, 8TB was the practical limit to file systems.

    It’s possible, though I haven’t confirmed, that this code snippet is a hangover from that transition, before the underlying data types went up to 64 bits wide.

    The type that came to be used, sector_t, was conditionally defined as either u64 or unsigned long, which may explain why the code is there in the first place. In situations where it was defined as the latter, a two-stage shift may have been needed.

    However, given that ext4 has left this interim stage behind, I’m not sure the two-stage shift is needed any more. Best bet is to raise a change request and see if it gets shot down by the developers 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

that's the code: static inline void shrinkData(const vector<Data> &data, unsigned short shrinkType){ #define CASE_N(N)
Minimal code: // --------inline.h-------- struct X { static inline void foo (); }; #ifdef
while calling this function: static inline void writel(unsigned int v, volatile void __iomem *addr)
static inline void *__memset(void *s, char c, size_t n) { int d0, d1; asm
Assume this code: static inline void inc(int64_t* atomic) { __asm__ __volatile__ ( lock incq
Consider the following code in linux/drivers/usb/hid-core.c: static void hid_process_event (struct hid_device *hid, struct hid_field
Lib1.a: #include<stdio.h> #include<stdlib.h> class Lib { public: inline static const void Test() { printf(this
I have two files: #include <stdio.h> static inline void print0() { printf(Zero); } static
static void testlock() { for(int i=0;i<10000000;i++) { float f=2.0/i; } } static void TEST()
static struct ipv6_devconf ipv6_devconf_dflt __read_mostly = { .forwarding = 0, .hop_limit = IPV6_DEFAULT_HOPLIMIT, .mtu6

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.